package 二分;

/**
 * H 指数 II
 * 这题 是真的 扯
 * 语文理解 问题 还是边界判断
 * @author I adore you
 *
 */
public class lc275 {

	public static void main(String []args) {
//		int citations [] = {0,1,3,5,6};
		int citations [] = {0};
		System.out.println(solution(citations));
		System.out.println(solutionNew(citations));
	}
	
	
	public static int solution(int arr[]) {
		
		int len = arr.length;
		int l = 0;
		int r = len - 1;
		int h = -1;
		if(arr[l + r >> 1] == 0)
			return 0;
		while(l <= r) {
			int mid = l + r >> 1;
			if(arr[mid] >= mid) {
				return mid + 1;
			}
			else {
				l = mid + 1;
			}
		
		}
		return -1;
		
	}
	
	public static int solutionNew(int arr[]) {
		int len = arr.length;
		int l = 0;
		int r = len -1;
		int ans = 0;
		while(l <= r) {
			int mid = l + r >> 1;
			if(arr[mid] >= len - mid) {
				ans = len - mid;
				r = mid - 1;
			}
			else {
				l = mid + 1;
			}
		}
		return ans;
	}
	
}
